package com.plume.toolbox.plus.ui.gallery;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.plume.toolbox.plus.CloudVActivity;
import com.plume.toolbox.plus.UserInfoSaver;
import com.plume.toolbox.plus.databinding.FragmentGalleryBinding;
import com.plume.toolbox.plus.R;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class GalleryFragment extends Fragment {

    private FragmentGalleryBinding binding;
    private Handler mHandler = new Handler(Looper.getMainLooper());
    

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {

        binding = FragmentGalleryBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        
        final Button btb_cloudV=binding.btnCloudv;
        
        btb_cloudV.setOnClickListener(v -> {
            if(!UserInfoSaver.checkLoginStatus(getActivity())){
                showToast("该功能必须登录才能使用!");
            }else{    
                showCloudVActivity();
            }        
        });
        
        return root;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
    
    private void showCloudVActivity(){
        Intent intent=new Intent(getActivity(),CloudVActivity.class);
        startActivity(intent);
    }
    
    public void showToast(final String message) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
            }
        });
    }
}